# require 'giftSpecList'
def updateNode list,node,arr
#   node = list.get_node(list.get_node_path(index))
# p node
  arr.each {|ar|
    node.iter[ar[0]]=ar[1]
  }
end
def updateList(list)
  list.array = []
  list.indices.each {|path|
# p path
    node = list.get_node(path)
# p node
    list.array << node.iter
  }
  begin
    list.refresh
  rescue
  end
end
def insertNode(list,node,new)
#    i = index
   a = list
   begin
#      node=a.get_node(a.get_node_path(i))
     if node.node_type==NODE_TYPE_EXPANDITEM
#        arr << node
       n = new
#        n = Node::new(5,NODE_TYPE_EXPANDITEM,a,node)
       n.set_index
p "==============="
       p n.get_index
# exit
       a.nodes[n]={}
       a.nodes[n]['index'] = n.get_index
#             f n.parent.expanded == 1
#        n.root.unexpand n.root
       expand = 1
       x = n.get_index.length
       parent = n.parent
       c = 0
       x.times do
         c = c + 1
         expand = expand * parent.expanded
         parent = parent.parent
       end
p expand.to_s+"pp"
if expand == 0
# exit
end
       if expand == 1
p "rr"
# exit
         if n.node_type == NODE_TYPE_EXPANDITEM
# p "hh"
# exit
         arr = n.get_index[0..n.get_index.length-1]
         else
          arr = n.get_index
         end
# p arr.last
         arr[arr.length-1]=arr.last-1
# p arr 
# exit   
#          index = a.indices.find_all {
         index = a.indices.find_all {|i| 
if i.length > arr.length
i = i[0..arr.length-1]
end
i == arr}
#  p index
index = index.last
# p n.get_index
# p "=========gg"
# exit
         index = a.indices.index(index) 
# p "hddddh"
# p index
# p n.iter
# exit
# n.parent.unexpand n.parent
         a.array.insert(index+1,n.iter)
# if n.get_index==[0,1,1]
# exit
# end
         a.indices.insert(index+1,n.get_index)
# n.parent.unexpand n.parent
# n.parent.reexpand n.parent
# p n.iter.to_s+"++"
# exit
a.refresh
       end

# n.parent.expanded = 1
#        n.parent.unexpand n.parent
# n.parent.expanded = 0
#        n.parent.reexpand n.parent
# n.parent.expanded = 1
#              n.root.reexpand n.root
            #              arr.each {|ar|
#                case ar[0]
#                  when 1
#                    ar[1].reexpend ar[1]
#                  else
#                    ar[1].unexpand
#                end
#              }
            
            
    end
  rescue
  end
end
